/*
 * @Description:
 * @Author: zhaokun
 * @Date: 2022-01-27 08:46:11
 * @LastEditTime: 2022-01-27 17:31:25
 * @FilePath: \user\rpc\internal\logic\getuserlogic.go
 */
package logic

import (
	"context"

	"user/models"
	"user/rpc/internal/svc"
	"user/rpc/user"

	"github.com/tal-tech/go-zero/core/jsonx"
	"github.com/tal-tech/go-zero/core/logx"
)

type GetUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserLogic {
	return &GetUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetUserLogic) GetUser(in *user.IdRequest) (*user.UserResponse, error) {
	// todo: add your logic here and delete this line
	userResponse := &user.UserResponse{}
	userModel := &models.User{}

	_, err := l.svcCtx.Model.ID(in.Id).Get(userModel)
	l.Logger.Infov(userModel)
	// l.Logger.Info(err.Error())
	userJson, _ := jsonx.Marshal(userModel)
	jsonx.Unmarshal(userJson, userResponse)
	return userResponse, err
}
